package com.example.compont;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.Editable;
import android.view.View;
import android.view.accessibility.AccessibilityManager;
import android.widget.EditText;
import android.widget.Toast;

public class EditTextActivity extends AppCompatActivity {
    private EditText mUserName, mPassWord;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit_text);

        mUserName = findViewById(R.id.mEditText);
        mPassWord = findViewById(R.id.mEditText1);
    }

    public void setSee(View view) {

    }

    public void logIn(View view) {
        Editable userName = mUserName.getText();
        Editable passWord = mPassWord.getText();

        if (userName.toString().isEmpty() || passWord.toString().isEmpty()){
            Toast.makeText(this, "用户名和密码不能为空", Toast.LENGTH_SHORT).show();
            return;
        }

        switch (checkUserNameAndPassWoedLength(userName.toString(), passWord.toString())) {
            case 1:
                Toast.makeText(this, "用户名长度不能大于10", Toast.LENGTH_SHORT).show();
                return;
            case 2:
                Toast.makeText(this, "密码长度不能大于10", Toast.LENGTH_SHORT).show();
                return;
            case 3:
                Toast.makeText(this, "用户名和密码长度不能大于10", Toast.LENGTH_SHORT).show();
                return;
            default:
                break;
        }

        Toast.makeText(this, "用户名：" + userName.toString() + "密码：" + passWord.toString(), Toast.LENGTH_LONG).show();
    }

    public int checkUserNameAndPassWoedLength(String username, String password) {
        int result = 0;

        if(username.length() > 10) {
            result += 1;
        }

        if(password.length() > 10) {
            result += 2;
        }
        return result;
    }
}